package com.example.AIstudy.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.AIstudy.domain.User;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {

    //根据用户名获取信息
    @Select("select * from user where nickname = #{nickname}")
    public User getUserByUserName(String nickname);

    @Select("select * from user where openID = #{openID}")
    public User getUserByOpenID(String openID);

    //新增一个用户信息，并且实现id回填
    @Insert("INSERT INTO user(openid,nickname,province,city,country,sex,selflevel,overlevel,headimgurl,description) " +
            "VALUES (#{openid},#{nickname},#{province},#{city},#{country},#{sex},#{selflevel},#{overlevel},#{headimgurl},#{description})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id",
            keyColumn = "id", resultType = Integer.class, before = false)
    void insertUser(User user);

    //分页获取用户信息
    @Select("SELECT * FROM user ${ew.customSqlSegment}")
    public IPage<User> findUsers(IPage<User> page,
                                 @Param(Constants.WRAPPER) QueryWrapper<User> wrapper);

    @Select("SELECT id FROM user")
    public List<Integer> getAllUserID();

}
